<template>
  <mu-container class="pos-r">
    <mu-row class="padt10">
      <mu-paper :z-depth="1" style="width: 100%" class="round5 pad5">
        <mu-flex align-items="center">
          <mu-flex>
            <mu-button icon @click="$goback()">
              <mu-icon value="arrow_back"></mu-icon>
            </mu-button>
          </mu-flex>
          <mu-flex fill><h3>管理员分组</h3></mu-flex>
          <mu-flex>
            <div class="padr10">
              <mu-button small fab color="primary" @click="submit()">
                <mu-icon value="save"></mu-icon>
              </mu-button>
            </div>
          </mu-flex>
        </mu-flex>
      </mu-paper>
    </mu-row>
    <mu-row class="padt10 pos-r" v-loading="loading">
      <mu-paper class="pad30" style="width: 100%" :z-depth="1">
        <!--        表单-->
        <formCreator :form.sync="form" :items="items" ></formCreator>
        <!--        表单-->
        <mu-row>
          <mu-button color="primary" @click="submit()">
            <mu-icon left value="save"></mu-icon>
            <span>提交保存</span>
          </mu-button>
        </mu-row>
      </mu-paper>
    </mu-row>
  </mu-container>

</template>

<script>
import api from '@/assets/js/api'
import formCreator from '@/components/FormCreator/Creator/Creator'

export default {
  name: 'adminGroupEdit',
  components: {formCreator},
  data () {
    return {
      id: undefined,
      form: {},
      items: {},
      loading: true
    }
  },
  created () {
  },
  mounted () {
    let _this = this
    this.id = this.$route.query.id
    let url = '/admin/AdminGroup/form'
    let id = this.id
    api.get(url, {id}, function (res) {
      _this.loading = false
      _this.form = res.d.show.entity
      _this.items = res.d.show.form
      console.log(res.d.show.form)
      console.log(res.d.show.entity)
    })
  },
  methods: {
    submit () {
      let _this = this
      this.loading = true
      api.post('/admin/AdminGroup/submit', this.form, function (res) {
        _this.loading = false
        if (res.s * 1 === 1) {
          _this.$goto('/admin/list/AdminGroupList')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
